#pragma once

#include <QVariant>
#include <QSqlQuery>
#include <QSqlError>

class FilterQuery : protected QSqlQuery
{
public:
	FilterQuery();
	FilterQuery(const QString &command);
public:
    QVariant nextValue();
    QVariant value(int i) const;
    bool next();
    void exec();
    bool prepare(const QString& query);
	void addBindValueWithoutFilter(const QString &val, QSql::ParamType type = QSql::In);
	template<typename T>
	void addBindValue(const T& val, QSql::ParamType type = QSql::In);
	void bindValue(const QString& placeholder, const QVariant& val,
		QSql::ParamType type = QSql::In);
	QString executedQuery() const;
	QVariant lastInsertId() const;
	int numRowsAffected() const;
    QSqlError lastError() const;
private:
    int _valueIndex = 0;
};

template<typename T>
void FilterQuery::addBindValue(const T& val, QSql::ParamType type /*= QSql::In*/)
{
	return QSqlQuery::addBindValue(val, type);
}
